<template>
  <div :style="defaultStyle" :class="isActiveClass">
    <div class="nav-list" :style="contentStyle">
      <div class="nav-item" v-for="(item, index) in contentData.default_sub_list" :key="index">
        <div class="left">
          <img v-if="contentData.show_icon" :src="item.leftIcon" class="icon" />
          <span class="label" :style="labelStyle">{{ item.title }}</span>
        </div>
        <div class="right">
          <img v-if="contentData.more_type === 1" :src="contentData.rightIcon" class="icon" />
          <span
            class="label"
            :style="{ color: contentData.more_text_color }"
            v-if="contentData.more_type === 2"
            >{{ contentData.show_more_text }}</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  const props = defineProps({
    contentData: {
      type: Object,
      default: () => ({})
    },
    isActiveClass: {
      type: String,
      default: ''
    }
  })

  const defaultStyle = computed(() => {
    const s = props.contentData.style
    return {
      paddingTop: s.paddingTop,
      paddingLeft: s.paddingLeft,
      paddingRight: s.paddingRight,
      paddingBottom: s.paddingBottom
    }
  })

  const contentStyle = computed(() => {
    const s = props.contentData.style
    return {
      borderRadius: s.borderRadius,
      backgroundColor: s.backgroundColor,
      overflow: 'hidden'
    }
  })

  const labelStyle = computed(() => {
    const s = props.contentData.itemStyle || {}
    return {
      color: s.color || '#333333',
      fontSize: s.fontSize ? `${s.fontSize}px` : '16px',
      fontWeight: s.fontWeight === 0 ? 'normal' : s.fontWeight
    }
  })
</script>

<style scoped lang="scss">
  .nav-list {
    padding: 6px;
  }

  .nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;

    &:last-child {
      border-bottom: none;
    }

    .left {
      display: flex;
      align-items: center;

      .icon {
        width: 20px;
        height: 20px;
        margin-right: 10px;
      }

      .label {
        font-size: 16px;
      }
    }

    .right {
      color: #999;
      font-size: 14px;

      .icon {
        width: 20px;
        height: 20px;
      }
    }
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
